<template>
	<view class="content">
		<view class="header" id="header">
			<view class="title">{{ num }}家可放款机构</view>
			<view class="header_tag">
				<text>免费申请</text>
				<text>极速下款</text>
			</view>
			<view class="dec">根据您的资质初步匹配以下产品，您可任意选择一个产品申请</view>
			<view class="header_dec">
				今日成功放款人数
				<text><u-count-to :start-val="1" :end-val="number" font-size="40rpx" color="#fff" :duration="1000" :use-easing="false"></u-count-to></text>
			</view>
			<image src="/static/zunxianglilv.png" lazy-load="false"></image>
		</view>
		<scroll-view class="scroll" scroll-y="true" :style="{ height: `${scrollH}px` }">
			<view class="scroll_item" v-for="(item, index) in listData" :key="index">
				<view class="item_check"><u-checkbox v-model="item.checked"></u-checkbox></view>
				<view class="item_content">
					<view class="item_title">
						<!-- <view class="img"></view> -->
						<image class="img" :src="item.logo" mode="aspectFit" lazy-load="false"></image>
						<view class="text">{{ item.name }}</view>
						<view class="tag">极速下款</view>
					</view>
					<view class="item_mid">
						<view class="limit">
							预估额度
							<text>{{ item.quota }}万</text>
						</view>
						<!-- <view class="product">
							<text style="color: #fc1f1f">8</text>
							款在线产品
						</view> -->
						<view class="number">
							<text>{{ item.consult }}</text>
							人
						</view>
					</view>
					<view class="item_b">
						<view class="">{{ item.apply_num }}人申请借款</view>
						<view class="">最低年利率{{ item.rate }}%</view>
						<view class="">近期咨询放款</view>
					</view>
				</view>
			</view>
		</scroll-view>
		<view class="footer" id="footer">
			<u-notice-bar mode="horizontal" type="primary" :volume-icon="false" :list="list"></u-notice-bar>
			<view class="agreement_flex">
				<u-checkbox v-model="checked" size="30" label-size="26rpx">已经阅读并同意</u-checkbox>
				<text @click="openAgrment">《贷款知情书》</text>
			</view>
			<view class="btn" @click="openView">立即申请借款</view>
		</view>
	</view>
</template>

<script>
import ajax from '@/api'
import { openView } from '@/utils'
export default {
	data() {
		return {
			checked: true,
			scrollH: 0,
			list: ['本产品为信贷产品，借款金额及利率根据用户具体信息评估后，由放款方和用户进行最后确认'],
			number: ((Min, Max) => {
				const Range = Max - Min
				const Rand = Math.random()
				const num = Min + Math.round(Rand * Range)
				return num
			})(501, 1299),
			num: '--',
			listData: [],
			tep: location.href.split('/')[3]
		}
	},
	mounted() {
		uni.getSystemInfo({
			success: (res) => {
				const query = uni.createSelectorQuery().select('#header')
				query
					.boundingClientRect((data) => {
						const info = uni.createSelectorQuery().select('#footer')
						info
							.boundingClientRect((ret) => {
								this.scrollH = res.windowHeight - (ret.height + data.height)
							})
							.exec()
					})
					.exec()
			}
		})
	},
	onShow() {
		this.init()
	},
	methods: {
		openAgrment() {
			// https://website.zd-dqd.com/dqdxy/#/pages/agreement/book
			// #ifdef H5
			let name = this.tep == 'xxl' ? 'book' : 'book1'
			location.href = `https://website.zd-dqd.com/dqdxy/#/pages/agreement/${name}`
			// #endif
		},
		init() {
			let data = JSON.parse(uni.getStorageSync('product'))
			data.row.forEach((item) => {
				item.checked = false
			})
			this.num = data.num
			this.listData = data.row
		},
		async openView() {
			if (!this.checked) {
				uni.showToast({
					title: '请先勾选贷款知情书',
					icon: 'none',
					position: 'bottom'
				})
				return
			}
			let data = this.listData.filter((v) => v.checked)
			if (!data.length) {
				uni.showToast({
					title: '请先选择你需要借贷的产品',
					icon: 'none',
					position: 'bottom'
				})
				return
			}
			let ids = data.map((item) => item.identification).join(',')
			await ajax.apply({ identification: ids, channel: uni.getStorageSync('id') || 3 })
			openView('/succee/succee', {})
		}
	}
}
</script>

<style lang="scss">
.item_b {
	margin-top: 6rpx;
}
.item_b view:nth-of-type(1) {
	font-size: 28rpx;
	font-family: PingFang SC;
	font-weight: 400;
	color: #969799;
}
.item_b view:nth-of-type(2) {
	font-size: 24rpx;
	font-family: PingFang SC;
	font-weight: bold;
	color: #ca9e6f;
}
.item_b view:nth-of-type(3) {
	font-size: 24rpx;
	font-family: PingFang SC;
	font-weight: 400;
	color: #969799;
}
.item_mid {
	.number {
		text {
			color: #696969;
		}
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: 800;
		color: #969799;
	}
	.limit {
		display: flex;
		align-items: center;
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #969799;
		text {
			margin-left: 8rpx;
			font-size: 48rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #3478f2;
		}
		.product {
			text {
				font-size: 24rpx;
				font-family: PingFang SC;
				font-weight: 800;
				color: #fc1f1f;
				margin-right: 2rpx;
			}
			font-size: 24rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #559ae2;
		}
	}
}
.item_title {
	display: flex;
	align-items: center;
	margin-bottom: 28rpx;
	.img {
		width: 44rpx;
		height: 44rpx;
		background: #3478f2;
		border-radius: 8rpx;
		margin-right: 20rpx;
	}
	.text {
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #333333;
	}
	.tag {
		margin-left: 10rpx;
		width: 112rpx;
		height: 32rpx;
		line-height: 32rpx;
		background: #eef4fe;
		opacity: 0.85;
		border-radius: 16rpx 16rpx 16rpx 0px;
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #969799;
		text-align: center;
	}
}
.item_b,
.item_mid {
	display: flex;
	justify-content: space-between;
	align-items: center;
}
.scroll {
	background: #fff;
	.scroll_item {
		padding: 32rpx 26rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		border-bottom: 1rpx solid #f3f3f3;
		.item_content {
			flex: 1;
			margin-left: 40rpx;
		}
	}
}
.header {
	position: relative;
	padding-left: 24rpx;
	padding-top: 38rpx;
	width: 100%;
	height: 412rpx;
	background: linear-gradient(180deg, #017eff 0%, #4a9df0 100%);
	image {
		width: 100%;
		height: 70rpx;
		position: absolute;
		left: 0;
		bottom: -1rpx;
	}
	.header_dec {
		margin-top: 24rpx;
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #ffffff;
		text {
			font-size: 40rpx;
			margin-left: 10rpx;
		}
	}
	.title {
		font-size: 40rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #ffffff;
	}
	.dec {
		margin-top: 24rpx;
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #ffffff;
	}
	.header_tag {
		margin-top: 24rpx;
		display: flex;
		align-items: center;
		text {
			width: 156rpx;
			height: 64rpx;
			line-height: 64rpx;
			background: #3478f2;
			border-radius: 24rpx;
			margin-right: 16rpx;
			font-size: 24rpx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #ffffff;
			text-align: center;
		}
	}
}
.footer {
	background: #fff;
	padding-bottom: 26rpx;
	.btn {
		width: 652rpx;
		height: 88rpx;
		line-height: 88rpx;
		background: #3478f2;
		margin: 36rpx auto;
		border-radius: 44rpx;
		text-align: center;
		font-size: 36rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #ffffff;
	}
}
.agreement_flex {
	margin-top: 36rpx;
	display: flex;
	align-items: center;
	justify-content: center;
	text {
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #3478f2;
		margin-left: -20rpx;
	}
}
</style>
